package crontab

import (
	"GOPAAS/internal/app/services"
	"GOPAAS/internal/utils"
	"fmt"
	"time"
)

func Test() {
	fmt.Println("every minutes")
}

// Schedule 定时任务
func Schedule() {
	crones := services.GetActiveCrones()
	for _, cron := range crones {
		if time.Now().After(utils.ForceCorrectTime(cron.NextCall)) && (cron.NumberCall.Valid && (cron.NumberCall.Int64 == -1 || cron.NumberCall.Int64 > 0)) {
			fmt.Println("开始发送邮件")
			MailService := services.GetMailService(1)
			err := MailService.SendMail("736025986@qq.com", "哈哈哈")
			if err == nil {
				fmt.Println("发送邮件成功")
				cron_service := services.GetCronService(cron.Id)
				//更新调度器
				cron_service.DecreaseCron()
			}
		}
	}

}
